using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CodeStory.Core.UI;
using CodeStory.Core;
using CodeStory.Core.ObjectBusiness;

namespace CodeStory.WebApplication.Modules.Core
{
	[NavigationPortlet("CodeStory_Core_RegisterUser")]
	public partial class RegisterUser : Portlet
	{
		protected override void OnInit(EventArgs e) {
			Load += new EventHandler(RegisterUser_Load);
			btnRegister.Click += new EventHandler(ButtonRegister_Click);
			base.OnInit(e);
		}

		void ButtonRegister_Click(object sender, EventArgs e) {
			if (txtConfirmPassword.Text != txtPassword.Text) {
				lblPassword.Text = "Password you entered was different.";
				return;
			}
			string msg = UserBusiness.RegisterUser(txtUserName.Text,txtPassword.Text,txtEmail.Text,txtPasswordQuestion.Text,txtPasswordAnswer.Text);
			if (!string.IsNullOrEmpty(msg)) {
				lblError.Text = msg;
			} else {
				CodeStory.Core.Authentication.CodeStoryAuthenticationManager.ValidateUser(txtUserName.Text, txtPassword.Text);
				Response.Redirect("~/default.aspx");
			}
		}

		void RegisterUser_Load(object sender, EventArgs e) {
		}
	}
}